package model;
import java.util.*;


/**
 * Write a description of class ProductContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ProductContainer
{
    private static ProductContainer instance;
    private ArrayList<Product> productList;

    private ProductContainer()
    {
        productList = new ArrayList<Product>();
    }

    public static ProductContainer getInstance()
    {
        if(instance == null)
        {
            instance = new ProductContainer();
        }
        return instance;
    }
    
    public void addProduct(Product product)
   {
        productList.add(product);
   }
   
   public ArrayList<Product> findProduct(String productName)
   {
       ArrayList<Product> pList = new ArrayList<Product>();
       for(Product p : productList)
       {
           if(p.getProductName().equals(productName))
           {
               pList.add(p);
           }
       }
       return pList;
   }
   
   public Product getProduct(String serial)
   {
       for(Product p : productList)
       {
           if(p.getSerialNumber().equals(serial))
           {
               return p;
            }
       }
       return null;
   }
   
   
   public void deleteProduct(Product product)
   {
       productList.remove(product);
   }
   
   public void updateProduct(String barcode, String productName, String productType,
                            double price, String location, String serialNumber, 
                            boolean availability){
        for(int i=0; i<productList.size(); i++) {
            if(productList.get(i).getBarcode().equals(barcode))
            {
               productList.get(i).setProductName(productName);
               productList.get(i).setProductType(productType);
               productList.get(i).setPrice(price);
               productList.get(i).setLocation(location);
               productList.get(i).setSerialNumber(serialNumber);
               productList.get(i).setAvailability(availability);
            }
        }
    }
    

}
